﻿Namespace UserControls
    Public Class SendTextUserControl
#Region "Form Event Handlers"
        Private Sub SendTextUserControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            VoicesComboBox.DataSource = NabaztagLib.Lookups.Voices.GetVoicesBindingSource
            SerialNumberTextBox.Text = My.Settings.DefaultSerialNumber
            TokenTextBox.Text = My.Settings.DefaultToken
        End Sub
#End Region

#Region "Child Control Event Handlers"
        Private Sub SendButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
            Dim message As NabazTagLib.Messages.IRequest = GetSimpleMessage()
            ResponseTextBox.Text = NabaztagLib.MessageService.SendMessage(message).ToString
        End Sub
#End Region

#Region "Methods"
        Private Function GetSimpleMessage() As NabaztagLib.Messages.IRequest
            Dim messageText As String = MessageTextBox.Text
            Dim serialNumber As String = SerialNumberTextBox.Text
            Dim token As String = Int32.Parse(TokenTextBox.Text)
            Dim voice As NabaztagLib.Lookups.VoiceEnum = NabaztagLib.Lookups.Voices.GetVoiceEnumFromDescription(VoicesComboBox.SelectedValue)
            Dim messageLifeInSeconds As String = MessageLifeNumericUpDown.Value
            Dim message As New NabaztagLib.Messages.SendTextRequest(serialNumber, token, messageText, voice, messageLifeInSeconds)
            Return message
        End Function
#End Region
    End Class
End Namespace